package com.xxtx.trade.web.userCenter;

import com.xxtx.trade.common.util.model.Result;
import com.xxtx.trade.sysUser.dto.KuaiShouInfoDto;
import com.xxtx.trade.sysUser.dto.TradeSysRoleDto;
import com.xxtx.trade.sysUser.service.TradeSysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("api/v1/xxtx/kuaishou")
public class SysKuaiShouController {

    @Autowired
    private TradeSysUserService tradeSysUserService;

    /*
     * 快手数据入口
     * */
    @RequestMapping(value = "/get/dianji/zj", method = RequestMethod.GET)
    public Result GetDianJiKuaiShou(HttpServletResponse response, HttpServletRequest request) {
        Result<Object> result = new Result<>();
        KuaiShouInfoDto dto = new KuaiShouInfoDto();
        String myName = request.getParameter("myName");
        if (myName == null || myName.equals("")) {
            result.setMessage("no url");
            return result;
        }
        dto.setUrlName(myName);

        String idfaMD5 = request.getParameter("idfaMD5");
        if (idfaMD5 == null) idfaMD5 = "";
        dto.setIdfaMD5(idfaMD5);

        String imeiMD5 = request.getParameter("imeiMD5");
        if (imeiMD5 == null) imeiMD5 = "";
        dto.setImeiMD5(imeiMD5);

        String callback = request.getParameter("callback");
        if (callback == null) callback = "";
        if (callback.length() > 250) {
            dto.setCallback(callback.substring(0, 250));
        } else {
            dto.setCallback(callback);
        }

        String accountid = request.getParameter("accountid");
        if (accountid == null) accountid = "";
        dto.setAccountid(accountid);

        String did = request.getParameter("did");
        if (did == null) did = "";
        dto.setDid(did);

        String aid = request.getParameter("aid");
        if (aid == null) aid = "";
        dto.setAid(aid);

        String cid = request.getParameter("cid");
        if (cid == null) cid = "";
        dto.setCid(cid);

        String dname = request.getParameter("dname");
        if (dname == null) dname = "";
        dto.setDname(dname);

        String unitname = request.getParameter("unitname");
        if (unitname == null) unitname = "";
        dto.setUnitname(unitname);

        String photoid = request.getParameter("photoid");
        if (photoid == null) photoid = "";
        dto.setPhotoid(photoid);

        String oaid2 = request.getParameter("oaid2");
        if (oaid2 == null) oaid2 = "";
        dto.setOaid2(oaid2);

        String os = request.getParameter("os");
        if (os == null) os = "";
        dto.setOs(os);

        String model = request.getParameter("model");
        if (model == null) model = "";
        dto.setModel(model);

        String ip = request.getParameter("ip");
        if (ip == null) ip = "";
        dto.setIp(ip);

        String csite = request.getParameter("csite");
        if (csite == null) csite = "";
        dto.setCsite(csite);


        tradeSysUserService.insertKuaiShouDatas(dto);

        return result;
    }

    @RequestMapping(value = "/list/permissionInfo", method = RequestMethod.POST)
    public Result permissionKuaiShouListInfo(@RequestBody TradeSysRoleDto tradeSysRoleDto) {
        return tradeSysUserService.kuaishouPermissionInfoList(tradeSysRoleDto);
    }

    @RequestMapping(value = "/permissionList/all", method = RequestMethod.POST)
    public Result permissionListAll(@RequestBody TradeSysRoleDto tradeSysRoleDto) {
        return tradeSysUserService.selectPermissionKuaiShouUrls(tradeSysRoleDto);
    }

}
